package com.android.nearshop.app.activity.search;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.android.nearshop.R;
import com.android.nearshop.app.activity.common.TemplateActivity;
import com.android.nearshop.app.adapter.listadapter.SearchHistoryAdapter;
import com.android.nearshop.app.widget.TitleBar;
import com.android.nearshop.app.widget.TitleBar.OnTitleClickListener;
import com.android.nearshop.util.Constant;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-8-14
 * @see : 历史记录activity
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class HistoryActivity extends TemplateActivity
{
	private ListView mList;
	
	public static final int CODE_REQUEST = 0x8805;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_search_history);	
		mList = (ListView) findViewById(R.id.list);
		mList.setAdapter(new SearchHistoryAdapter(this));
		
		mList.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				TextView text = (TextView) view.findViewById(R.id.tab_tx);
				Intent intent = new Intent();
				intent.putExtra(Constant.TAG_SREACH_HISTORY, text.getText());
				
				setResult(RESULT_OK, intent);
				finish();
			}
		});
	}
	
	@Override
	protected void setupTitleBar(TitleBar titleBar)
	{
	    titleBar.setTitle(R.string.search_history);
	    titleBar.setRigthText(R.string.tx_setting);
	    titleBar.setOnTitleClickListener(new OnTitleClickListener() 
	    {
            //返回历史记录
            public void onRightClick() 
            {
            	
            }
            //返回主页面
            public void onLeftClick() 
            {
                Intent intent = new Intent();
                intent.setClass(getApplicationContext(), SearchActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
                finish();
            }
        },true, true);
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		mList.setAdapter(null);
	}
	
}
